package com.hiultra.archive.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hiultra.archive.domain.*;
import com.hiultra.archive.domain.vo.ArchiveStocktakingTaskIssuedVo;
import com.hiultra.archive.domain.vo.ArchiveUploadTaskIssuedVo;
import com.hiultra.archive.domain.vo.ArchiveUploadTaskReportVo;
import com.hiultra.archive.domain.vo.ResultEntity;
import com.hiultra.archive.mapper.*;
import com.hiultra.archive.service.*;
import com.hiultra.archive.utils.sgsm.SM2Util;
import com.hiultra.archive.utils.tool.ToolUtils;
import com.hiultra.common.constant.BusinessConstants;
import com.hiultra.common.exception.ServiceException;
import com.hiultra.common.utils.DateUtils;
import com.hiultra.common.utils.uuid.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;

/**
 * 转存任务Service业务层处理
 *
 * @author paidaxing
 * @date 2024-07-24
 */
@Service
public class ArchiveUploadTaskServiceImpl implements IArchiveUploadTaskService {
    private static final Logger log = LoggerFactory.getLogger(ArchiveUploadTaskServiceImpl.class);
    @Autowired
    private ArchiveUploadTaskMapper archiveUploadTaskMapper;
    @Autowired
    private ArchiveCabinetMapper archiveCabinetMapper;
    @Autowired
    private ArchiveArchAreaMapper archiveArchAreaMapper;
    @Autowired
    private ArchiveUploadTaskBoxMapper uploadTaskBoxMapper;
    @Autowired
    private IArchiveUploadTaskBoxService archiveUploadTaskBoxService;
    @Autowired
    private IArchiveUploadTaskBagService archiveUploadTaskBagService;
    @Autowired
    private IArchiveUploadTaskArchiveService archiveUploadTaskArchiveService;
    @Autowired
    private IArcBoxService arcBoxService;
    @Autowired
    private IArchiveBagService archiveBagService;
    @Autowired
    private IRoomArchiveService roomArchiveService;

    @Value("${roomNo}")
    private String roomNo;
    @Value("${priKey}")
    private String priKey;
    @Value("${pubKey}")
    private String pubKey;
    @Value("${urlIp}")
    private String urlIp;
    @Value("${archiveUploadTaskResultReportUrl}")
    private String archiveUploadTaskResultReportUrl;

    /**
     * 查询转存任务
     *
     * @param taskId 转存任务主键
     * @return 转存任务
     */
    @Override
    public ArchiveUploadTask selectArchiveUploadTaskByTaskId(String taskId) {
        return archiveUploadTaskMapper.selectArchiveUploadTaskByTaskId(taskId);
    }

    /**
     * 通过单号查询转存任务
     *
     * @param transferNo 转存任务编号
     * @return 转存任务
     */
    @Override
    public ArchiveUploadTask selectArchiveUploadTaskByTaskNo(String transferNo) {
        return archiveUploadTaskMapper.selectArchiveUploadTaskByTaskNo(transferNo);
    }

    /**
     * 查询转存任务列表
     *
     * @param archiveUploadTask 转存任务
     * @return 转存任务
     */
    @Override
    public List<ArchiveUploadTask> selectArchiveUploadTaskList(ArchiveUploadTask archiveUploadTask) {
        return archiveUploadTaskMapper.selectArchiveUploadTaskList(archiveUploadTask);
    }

    /**
     * 新增转存任务
     *
     * @param archiveUploadTask 转存任务
     * @return 结果
     */
    @Override
    public int insertArchiveUploadTask(ArchiveUploadTask archiveUploadTask) {
        archiveUploadTask.setCreateTime(DateUtils.getNowDate());
        return archiveUploadTaskMapper.insertArchiveUploadTask(archiveUploadTask);
    }

    /**
     * 修改转存任务
     *
     * @param archiveUploadTask 转存任务
     * @return 结果
     */
    @Override
    public int updateArchiveUploadTask(ArchiveUploadTask archiveUploadTask) {
        return archiveUploadTaskMapper.updateArchiveUploadTask(archiveUploadTask);
    }

    /**
     * 批量删除转存任务
     *
     * @param taskIds 需要删除的转存任务主键
     * @return 结果
     */
    @Override
    public int deleteArchiveUploadTaskByTaskIds(String[] taskIds) {
        return archiveUploadTaskMapper.deleteArchiveUploadTaskByTaskIds(taskIds);
    }

    /**
     * 删除转存任务信息
     *
     * @param taskId 转存任务主键
     * @return 结果
     */
    @Override
    public int deleteArchiveUploadTaskByTaskId(String taskId) {
        return archiveUploadTaskMapper.deleteArchiveUploadTaskByTaskId(taskId);
    }

    /**
     * 转存任务结果上报接口
     *
     * @param archiveUploadTask
     * @return
     */
    @Override
    public int archiveUploadTaskResultReport(ArchiveUploadTask archiveUploadTask) throws JsonProcessingException {
        if (ObjectUtil.isNull(archiveUploadTask.getReportType())) {
            throw new ServiceException("上报类型为空，请检查重试");
        }
        //查询档案任务信息
        ArchiveUploadTask uploadTask = archiveUploadTaskMapper.selectArchiveUploadTaskbyTransferNo(archiveUploadTask.getTransferNo());
        if (null == uploadTask) {
            throw new ServiceException("不存在此工单任务，请检查后重试！");
        }
        if (BusinessConstants.TRANSFERREPORTTYPE.equals(archiveUploadTask.getReportType())) {
            //出库上报
            //判断是否是出库档案室匹配当前档案室
            if (!roomNo.equals(uploadTask.getTransferOutRoomNo())) {
                throw new ServiceException("工单编号为" + uploadTask.getTransferNo() + "非出库档案室可操作任务，请检查重试！");
            }
            //判断工单推送状态，如果已经推送了就不能重复推送了
            if (BusinessConstants.END_PUSHSTATUS.equals(uploadTask.getPushStatus())) {
                throw new ServiceException("工单编号为" + uploadTask.getTransferNo() + "已经出库上报，请勿重复提交！");
            }
        } else {
            if (!roomNo.equals(uploadTask.gettransferInRoomNo())) {
                throw new ServiceException("工单编号为" + uploadTask.getTransferNo() + "非出库档案室可操作任务，请检查重试！");
            }
            //判断工单推送状态，如果已经推送了就不能重复推送了
            if (BusinessConstants.END_PUSHSTATUS.equals(uploadTask.getInPushStatus())) {
                throw new ServiceException("工单编号为" + uploadTask.getTransferNo() + "已经入库上报，请勿重复提交！");
            }
        }

        ArchiveUploadTaskReportVo archiveUploadTaskReportVo = ToolUtils.convertEntity(uploadTask, ArchiveUploadTaskReportVo::new);

        if (ObjectUtil.isNotNull(uploadTask.getTransferTime())) {
            archiveUploadTaskReportVo.setTransferTime(DateUtil.format(uploadTask.getTransferTime(), "yyyyMMddHHmmss"));
        }
        // 将JsonData对象转换为JSON字符串
        String jsonString = new ObjectMapper().writeValueAsString(archiveUploadTaskReportVo);
        System.out.println("转存结果上报" + jsonString);

        //发送请求获取数据
        HashMap hashMap = ToolUtils.sendPostRequest(BusinessConstants.ARCHIVE_UPLOAD_TASK_TASK_REPORT_NO, urlIp, archiveUploadTaskResultReportUrl, "转存任务上报接口", jsonString, pubKey, priKey);
        //判断是否成功
        if (hashMap == null || !hashMap.containsKey("code") || !hashMap.get("code").equals("00000")) {
            System.out.println("转存任务结果上报失败");
            throw new ServiceException(hashMap.get("message").toString());
        }
        System.out.println("转存任务结果上报接口成功");
        if (BusinessConstants.TRANSFERREPORTTYPE.equals(archiveUploadTask.getReportType())) {
            uploadTask.setPushStatus(BusinessConstants.END_PUSHSTATUS);
        } else {
            uploadTask.setInPushStatus(BusinessConstants.END_PUSHSTATUS);
        }
        return archiveUploadTaskMapper.updateArchiveUploadTask(uploadTask);
    }


    /**
     * 转存移位任务下发接口
     *
     * @param data
     * @return 结果
     */
    @Override
    public ResultEntity insertIssuedArchiveUploadTask(String data) throws ParseException {
        //解密
        System.out.println("转存移位任务下发数据：" + data);
        String decryptedResult = new SM2Util().decryptBySM2(data, priKey);
        System.out.println("转存移位任务下发解密结果：" + decryptedResult);

        ArchiveUploadTaskIssuedVo archiveUploadTaskIssuedVo = JSON.parseObject(decryptedResult.trim(), ArchiveUploadTaskIssuedVo.class);
        if (ObjectUtil.isNull(archiveUploadTaskIssuedVo)) {
            // 返回错误信息或抛出异常
            log.info("入参解析出错，请检查重试");
            return ResultEntity.error("入参解析出错，请检查重试");
        }
        try {
            processArchiveUploadTask(archiveUploadTaskIssuedVo);
        } catch (ServiceException e) {
            e.printStackTrace();
            return ResultEntity.error(e.getMessage());
        }
        return ResultEntity.success();
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void processArchiveUploadTask(ArchiveUploadTaskIssuedVo archiveUploadTaskIssuedVo) {
        try {
            if (ObjectUtil.isNotNull(archiveUploadTaskIssuedVo)) {
                ArchiveUploadTask archiveUploadTask = ToolUtils.convertEntity(archiveUploadTaskIssuedVo, ArchiveUploadTask::new);

                ArchiveUploadTask archiveUploadTask1 = selectArchiveUploadTaskByTaskNo(archiveUploadTask.getTransferNo());
                //不存在则新增
                if (null == archiveUploadTask1) {
                    List<ArchiveUploadTaskIssuedVo.ArchiveBox> archiveBoxes = archiveUploadTaskIssuedVo.getBoxList();
                    List<ArchiveUploadTaskIssuedVo.Archive> archives = archiveUploadTaskIssuedVo.getArchList();
                    archiveUploadTask.setTaskId(UUID.randomUUID().toString().replace("-", ""));
                    //根据出入库状态设置推送状态
                    if (BusinessConstants.UPLOADSTATUSOUT.equals(archiveUploadTaskIssuedVo.getStatus())) {
                        //待出库------处理逻辑
                        archiveUploadTask.setPushStatus(BusinessConstants.PUSHSTATUS);
                        archiveUploadTask.setTransferStatus(BusinessConstants.PRETRANSFERSTATUSOUT);
                        archiveUploadTask.setTransferOutRoomNo(roomNo);
                        //非空
                        if (archiveBoxes.size() > 0) {
                            for (ArchiveUploadTaskIssuedVo.ArchiveBox archiveBox : archiveBoxes) {
                                //判断转入还是转出status 01待出库 02待入库
                                ArchiveUploadTaskBox archiveUploadTaskBox = new ArchiveUploadTaskBox();
                                archiveUploadTaskBox.setId(UUID.randomUUID().toString().replace("-", ""));
                                archiveUploadTaskBox.setTaskId(archiveUploadTask.getTaskId());
                                //根据boxid获取box信息
                                ArcBox arcBox = arcBoxService.selectArcBoxByBoxId(archiveBox.getBoxId());
                                //判空
                                if (ObjectUtil.isNull(arcBox)) {
                                    log.info("档案盒标识" + archiveBox.getBoxId() + "不存在,请检查重试!");
                                    throw new ServiceException("档案盒标识" + archiveBox.getBoxId() + "不存在,请检查重试！");
                                }
                                //补全
                                archiveUploadTaskBox.setBoxBarCode(arcBox.getBoxRfid());
                                archiveUploadTaskBox.setCustNo(arcBox.getCustNo());
                                archiveUploadTaskBox.setBoxNo(arcBox.getBoxCode());
                                archiveUploadTaskBox.setHouseLocationNo(arcBox.getHouseLocationNo());

                                archiveUploadTaskBox.setStatus(BusinessConstants.PRETRANSFERSTATUSOUT);
                                //新增
                                archiveUploadTaskBoxService.insertArchiveUploadTaskBox(archiveUploadTaskBox);
                            }
                        }

                        if (archives.size() > 0) {
                            for (ArchiveUploadTaskIssuedVo.Archive archive : archives) {
                                //判断转入还是转出status 01待出库 02待入库
                                ArchiveUploadTaskArchive archiveUploadTaskArchive = new ArchiveUploadTaskArchive();
                                archiveUploadTaskArchive.setId(UUID.randomUUID().toString().replace("-", ""));
                                archiveUploadTaskArchive.setTaskId(archiveUploadTask.getTaskId());
                                RoomArchive roomArchive = roomArchiveService.selectRoomArchiveById(archive.getArchiveId());
                                if (ObjectUtil.isNull(roomArchive)) {
                                    log.info("档案标识" + archive.getArchiveId() + "不存在,请检查重试!");
                                    throw new ServiceException("档案标识" + archive.getArchiveId() + "不存在,请检查重试！");
                                }
                                archiveUploadTaskArchive.setArchName(roomArchive.getArchiveName());
                                archiveUploadTaskArchive.setBoxNo(roomArchive.getBoxNo());
                                archiveUploadTaskArchive.setHouseLocationNo(roomArchive.getHouseLocationNo());
                                archiveUploadTaskArchive.setCustNo(roomArchive.getArchObjNo());

                                if (BusinessConstants.UPLOADSTATUSIN.equals(archiveUploadTaskIssuedVo.getStatus())) {
                                    //根据inBoxId 获取box信息
                                    ArcBox arcBox = arcBoxService.selectArcBoxByBoxId(archive.getInBoxId());
                                    //判空
                                    if (ObjectUtil.isNull(arcBox)) {
                                        throw new ServiceException("档案盒标识" + archive.getInBoxId() + "不存在,请检查重试！");
                                    }
                                    archiveUploadTaskArchive.setStatus(BusinessConstants.PRETRANSFERSTATUSIN);
                                    archiveUploadTaskArchive.setInBoxNo(arcBox.getBoxCode());
                                    archiveUploadTaskArchive.setInHouseLocationNo(archive.getInHouseLocationNo());
                                } else {
                                    archiveUploadTaskArchive.setStatus(BusinessConstants.PRETRANSFERSTATUSOUT);
                                }

                                //新增
                                archiveUploadTaskArchiveService.insertArchiveUploadTaskArchive(archiveUploadTaskArchive);
                            }
                        }

                    } else {
                        //待入库--------------------------------处理逻辑
                        archiveUploadTask.setTransferStatus(BusinessConstants.PRETRANSFERSTATUSIN);
                        archiveUploadTask.settransferInRoomNo(roomNo);
                        archiveUploadTask.setInPushStatus(BusinessConstants.PUSHSTATUS);
                        for (ArchiveUploadTaskIssuedVo.ArchiveBox archiveBox : archiveBoxes) {
                            ArchiveUploadTaskBox archiveUploadTaskBox = new ArchiveUploadTaskBox();
                            archiveUploadTaskBox.setId(UUID.randomUUID().toString().replace("-", ""));
                            archiveUploadTaskBox.setTaskId(archiveUploadTask.getTaskId());
                            //根据boxid获取box信息
                            ArcBox arcBox = ToolUtils.convertEntity(archiveBox, ArcBox::new);
                            ArchiveCabinet archiveCabinet = archiveCabinetMapper.selectArchiveCabinetById(archiveBox.getCabinetId());
                            if (ObjectUtil.isEmpty(archiveCabinet)) {
                                log.info("未找到此档案盒所属档案柜标识" + archiveBox.getCabinetId() + "信息，请检查重试！");
                                throw new ServiceException("未找到此档案盒所属档案柜标识" + archiveBox.getCabinetId() + "信息，请检查重试！");
                            }

                            arcBox.setCabinetNo(archiveCabinet.getColNo());
                            arcBox.setBoxCode(archiveBox.getBoxNo());
                            arcBox.setBoxRfid(archiveBox.getBoxBarCode());
                            //todo文档中是档案盒条码和rfid两个字段
                            arcBox.setSpecs(archiveBox.getBoxSpec());
                            arcBox.setBoxStatus(archiveBox.getBoxStat());
                            arcBox.setBoxStatus(!archiveBox.getBoxStat().isEmpty() ? archiveBox.getBoxStat() : BusinessConstants.BOX_STAT_PRE);
                            //设置保管期限默认值
                            arcBox.setKeepDur(!archiveBox.getKeepDur().isEmpty() ? archiveBox.getKeepDur() : BusinessConstants.BOX_PERIOD_FOREVER);
                            //设置保管级别默认值
                            arcBox.setConfdLv(!archiveBox.getConfdLv().isEmpty() ? archiveBox.getConfdLv() : BusinessConstants.BOX_SECRET_PUBLIC);
                            ArchiveArchArea archiveArchArea = archiveArchAreaMapper.selectArchiveArchAreaById(archiveBox.getAreaId());
                            if (ObjectUtil.isEmpty(archiveArchArea)) {
                                log.info("未找到此档案盒所属档案区标识" + archiveBox.getAreaId() + "信息，请检查重试！");
                                throw new ServiceException("未找到此档案盒所属档案区标识" + archiveBox.getAreaId() + "信息，请检查重试！");
                            }
                            arcBox.setAreaNo(archiveArchArea.getArchAreaNo());
                            //设置默认值
                            arcBox.setGiveBackStatus(BusinessConstants.PRE_GIVE_BACK_STATUS);
                            arcBox.setStatus(BusinessConstants.PRE_IS_WRITE_CARD);
                            int insertBox = arcBoxService.insertArcBox(arcBox);
                            //判空
                            if (insertBox == 1) {
                                //补全
                                archiveUploadTaskBox.setBoxBarCode(arcBox.getBoxRfid());
                                archiveUploadTaskBox.setCustNo(arcBox.getCustNo());
                                archiveUploadTaskBox.setBoxNo(arcBox.getBoxCode());
                                archiveUploadTaskBox.setHouseLocationNo(arcBox.getHouseLocationNo());
                                archiveUploadTaskBox.setInHouseLocationNo(archiveBox.getInHouseLocationNo());
                                archiveUploadTaskBox.setStatus(BusinessConstants.PRETRANSFERSTATUSIN);
                            }

                            //新增
                            archiveUploadTaskBoxService.insertArchiveUploadTaskBox(archiveUploadTaskBox);

                            if (archives.size() > 0) {
                                for (ArchiveUploadTaskIssuedVo.Archive archive : archives) {
                                    //判断转入还是转出status 01待出库 02待入库
                                    ArchiveUploadTaskArchive archiveUploadTaskArchive = new ArchiveUploadTaskArchive();
                                    archiveUploadTaskArchive.setId(UUID.randomUUID().toString().replace("-", ""));
                                    archiveUploadTaskArchive.setTaskId(archiveUploadTask.getTaskId());
                                    RoomArchive roomArchive = ToolUtils.convertEntity(archive, RoomArchive::new);

                                    roomArchive.setId(archive.getArchiveId());
                                    //设置借阅状态默认值
                                    roomArchive.setGiveBackStatus(BusinessConstants.PRE_GIVE_BACK_STATUS);
                                    roomArchive.setCabinetNo(arcBox.getCabinetNo());
                                    roomArchive.setAreaNo(arcBox.getAreaNo());
                                    roomArchive.setBoxNo(arcBox.getBoxCode());
                                    roomArchive.setArchiveName(archive.getArchName());
                                    roomArchive.setArchiveType(archive.getArchType());
                                    roomArchive.setConLevel(archive.getConfdLv());
                                    roomArchive.setSaveDate(archive.getKeepDur());
                                    roomArchive.setDelflag(BusinessConstants.DELFLAG);

                                    int insertArchive = roomArchiveService.insertRoomArchive(roomArchive);
                                    if (insertArchive == 1) {
                                        archiveUploadTaskArchive.setArchName(roomArchive.getArchiveName());
                                        archiveUploadTaskArchive.setBoxNo(roomArchive.getBoxNo());
                                        archiveUploadTaskArchive.setHouseLocationNo(roomArchive.getHouseLocationNo());
                                        archiveUploadTaskArchive.setCustNo(roomArchive.getArchObjNo());
                                        archiveUploadTaskArchive.setStatus(BusinessConstants.PRETRANSFERSTATUSIN);
                                        archiveUploadTaskArchive.setInBoxNo(arcBox.getBoxCode());
                                        archiveUploadTaskArchive.setInHouseLocationNo(archive.getInHouseLocationNo());
                                    }
                                    archiveUploadTaskArchiveService.insertArchiveUploadTaskArchive(archiveUploadTaskArchive);
                                }
                            }
                        }

                    }
                    insertArchiveUploadTask(archiveUploadTask);


                    //处理档案袋
//                List<ArchiveUploadTaskIssuedVo.ArchiveBag> archiveBags = archiveUploadTaskIssuedVo.getBagList();
//                if (archiveBags.size() > 0) {
//                    for (ArchiveUploadTaskIssuedVo.ArchiveBag archiveBag : archiveBags) {
//                        //判断转入还是转出status 01待出库 02待入库
//                        ArchiveUploadTaskBag archiveUploadTaskBag = new ArchiveUploadTaskBag();
//                        archiveUploadTaskBag.setId(UUID.randomUUID().toString().replace("-", ""));
//                        archiveUploadTaskBag.setTaskId(archiveUploadTask.getTaskId());
//                        ArchiveBag archiveBag1 = archiveBagService.selectArchiveBagByBagId(archiveBag.getBagId());
//                        if (ObjectUtil.isNull(archiveBag1)) {
//                            log.info("档案袋标识" + archiveBag.getBagId() + "不存在,请检查重试!");
//                            throw new ServiceException("档案袋标识" + archiveBag.getBagId() + "不存在,请检查重试！");
//                        }
//                        archiveUploadTaskBag.setBagId(archiveBag1.getBagId());
//                        archiveUploadTaskBag.setBagCode(archiveBag1.getBagCode());
//                        archiveUploadTaskBag.setBagNo(archiveBag1.getBagNo());
//                        archiveUploadTaskBag.setBoxNo(archiveBag1.getBoxNo());
//                        archiveUploadTaskBag.setCustNo(archiveBag1.getCustNo());
//                        ArcBox arcBoxo = arcBoxService.selectArcBoxByBoxId(archiveBag1.getBoxId());
//
//                        //判空
//                        if (ObjectUtil.isNull(arcBoxo)) {
//                            log.info("档案盒标识" + archiveBag1.getBoxId() + "不存在,请检查重试!");
//                            throw new ServiceException("档案盒标识" + archiveBag1.getBoxId() + "不存在,请检查重试！");
//                        }
//                        archiveUploadTaskBag.setHouseLocationNo(arcBoxo.getHouseLocationNo());
//                        archiveUploadTaskBag.setInBoxNo(arcBoxo.getBoxCode());
//                        if (BusinessConstants.UPLOADSTATUSIN.equals(archiveUploadTaskIssuedVo.getStatus())) {
//                            //根据inBoxId 获取box信息
//                            ArcBox arcBox = arcBoxService.selectArcBoxByBoxId(archiveBag.getInBoxId());
//
//                            //判空
//                            if (ObjectUtil.isNull(arcBox)) {
//                                log.info("档案盒标识" + archiveBag.getInBoxId() + "不存在,请检查重试!");
//                                throw new ServiceException("档案盒标识" + archiveBag.getInBoxId() + "不存在,请检查重试！");
//                            }
//                            archiveUploadTaskBag.setStatus(BusinessConstants.PRETRANSFERSTATUSIN);
//                            archiveUploadTaskBag.setHouseLocationNo(arcBox.getHouseLocationNo());
//                            archiveUploadTaskBag.setInBoxNo(arcBox.getBoxCode());
//                            archiveUploadTaskBag.setInHouseLocationNo(archiveBag.getInHouseLocationNo());
//                        } else if (BusinessConstants.UPLOADSTATUSOUT.equals(archiveUploadTaskIssuedVo.getStatus())) {
//                            archiveUploadTaskBag.setStatus(BusinessConstants.PRETRANSFERSTATUSOUT);
//                        }
//                        //新增
//                        archiveUploadTaskBagService.insertArchiveUploadTaskBag(archiveUploadTaskBag);
//                    }
//                }


                } else {
                    //todo修改
                    archiveUploadTaskMapper.updateArchiveUploadTask(archiveUploadTask);
                    System.out.println("修改");
                }
            }
        } catch (ServiceException e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new ServiceException(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new ServiceException("发生未知异常，事务已回滚"+e.getMessage());
        }
    }

    /**
     * 转存移位任务下发接口
     *
     * @return 结果
     */
    @Override
    public ResultEntity timingArchiveUploadTaskResultReport() {
        List<ArchiveUploadTask> archiveUploadTaskList = archiveUploadTaskMapper.selectArchiveUploadTaskList(new ArchiveUploadTask() {{
            setPushStatus(BusinessConstants.PUSHSTATUS);
        }});
        if (archiveUploadTaskList.size() > 0) {
            for (ArchiveUploadTask archiveUploadTask : archiveUploadTaskList) {
                try {
                    archiveUploadTaskResultReport(archiveUploadTask);
                } catch (JsonProcessingException e) {
                    e.printStackTrace();
                }
            }
        }
        return ResultEntity.success();
    }

}
